package datastructure_algorithm.sort;

public class SelectionSort {

	public static void sort(Integer[] arr) {
		int n = arr.length;
		for (int i = 0; i < n; i++) {
			int minIndex = i;
			for (int j = i + 1; j < n; j++) {
				if (arr[j] > arr[minIndex]) {
					minIndex = j;
				}
			}
			swap(arr, i, minIndex);
		}
	}

	private static void swap(Integer[] arr, int i, int minIndex) {
		int t = arr[i];
		arr[i] = arr[minIndex];
		arr[minIndex] = t;
	}

}
